<!doctype html>
<html>
<head>
    <include file="public/head"/>
    <title>千佰特自定义模型管理</title>
    <meta name="description" content="千佰特自定义模型管理">
    <meta name="keywords" content="千佰特自定义模型管理">
</head>
<body>
<div class="wrap js-check-wrap">
<form method="post" action="#" id="uploadForm" enctype="multipart/form-data">
    <ul class="nav nav-tabs">
        <li class="active"><a>模型管理</a></li>
        <li><a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/add')}">添加模型</a></li>
        <li>
			<input id="file" type="file" name="file" style="display:none;" onchange="file_upload()"/>
			<a href="#" onclick="selectFile()">导入模型</a>
		</li>
    </ul>
	</form>
    <form method="post" class="js-ajax-form margin-top-20" action="">
        <div class="table_list">
			<div class="table-actions">
				<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
						data-action="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/export')}" data-subcheck="true">导出空模型
				</button>
				<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
						data-action="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/export_data')}" data-subcheck="true">导出带数据模型
				</button>
			</div>
            <table width="100%" class="table table-hover">
                <thead>
                <tr>
					<th width="15">
						<label>
							<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
						</label>
					</th>
                    <th>名称</th>
                    <th>表名</th>
                    <th>控制器名</th>
                    <th>模型分类</th>
                    <th>描述</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
				<?php if($model_list):?>
					<?php foreach($model_list as $val):?>
					<tr>
					<td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$val.model_id}" title="ID:{$val.model_id}">
                    </td>
						<td><?=$val['model_name']?></td>
						<td><?=$val['model_tabname']?></td>
						<td><?=$val['model_controller']?></td>
						<?php if($val['distinguish']==1):?>
						<td>分类模型</td>
						<?php elseif($val['distinguish']==2):?>
						<td>信息模型</td>
						<?php endif;?>
						<td><?=$val['model_description']?></td>
						<td><?=date("Y-m-d H:i:s",$val['addtime'])?></td>
						<td>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/rebuild',['model_id'=>$val['model_id']])}"  class="js-ajax-dialog-btn" data-msg="确定更新该模型吗？<br/>更新之后将重新生成相关文件">更新模型</a>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminModelField/lists',['model_id'=>$val['model_id']])}">字段管理</a>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/copy',['model_id'=>$val['model_id']])}" >复制</a>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/GenerateMenu',['model_id'=>$val['model_id']])}" class="js-ajax-dialog-btn" data-msg="确定更新或生成菜单？">{$val.is_menu?'更新菜单':'生成菜单'}</a>
							<?php if($val['model_type'] == 1):?>
							<a href="javascript:alert('内置模型不允许编辑')">编辑</a>
							<a href="javascript:alert('内置模型不允许删除')">删除</a>
							<?php else:?>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/edit',['model_id'=>$val['model_id']])}">编辑</a>
							<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/delete',['model_id'=>$val['model_id']])}'}" class="js-ajax-delete">删除</a>
							<?php endif;?>
						</td>
					</tr>
					<?php endforeach;?>
				<?php else:?>
				 <tr><td colspan="4">尚未添加模型，<a href="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/add')}">立即添加</a></td></tr>
				<?php endif;?>
                </tbody>
            </table>
			<div class="table-actions">
				<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
						data-action="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/export')}" data-subcheck="true">导出空模型
				</button>
				<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
						data-action="{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/export_data')}" data-subcheck="true">导出带数据模型
				</button>
			</div>
        </div>
    </form>
	<div style="text-align:center;">
		<ul class="pagination">{$page}</ul>
	</div>
</div>
<script type="text/javascript" src="__STATIC__/js/layer/layer.js" > </script>
<script type="text/javascript">
function selectFile(){
$("#file").click()
}

function file_upload(){
$.ajax({
    url: "{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/import_model')}",
    type: 'POST',
    cache: false,
    data: new FormData($('#uploadForm')[0]),
    processData: false,
    contentType: false,
	success:function(msg){
		var res=JSON.parse(msg);
		if(res.status == 1){
			$.get("{:cmf_plugin_url('QbtCustomModel://AdminQbtCustomModel/delFile')}",{err:1},function (res) {
			    layer.msg('导入成功');
                setTimeout(function () {  //使用  setTimeout（）方法设定定时2000毫秒
                    layer.closeAll();
                    window.location.reload();//页面刷新
                }, 2000);
            })
		}else{
			layer.msg(res.msg);
		}
	}
}).done(function(res) {}).fail(function(res) {}); 

}
</script>
<include file="public/scripts"/>
</body>
</html>